package com.onpositive.dataminer.rcp.views;

import java.util.ArrayList;

import com.onpositive.dataminer.core.DefaultUniverse;
import com.onpositive.dataminer.core.HasEnoughData;
import com.onpositive.dataminer.core.PropertyRateAuditResult;
import com.onpositive.knowledge.model.value.audits.AbstractAuditResult;
import com.onpositive.knowledge.model.value.audits.ContradictionsDetectionAudit;
import com.onpositive.knowledge.model.value.audits.DisambiguationValueAudit;
import com.onpositive.knowledge.model.value.audits.GeneralAuditResult;
import com.onpositive.knowledge.model.value.audits.RangeAuditResult;
import com.onpositive.knowledge.model.values.ReplacementProposals;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.semantic.model.binding.Binding;

public class PropertyAudits extends PropertyView {

	public PropertyAudits() {
		super("ui/propertyAudits.dlf");
	}

	

	public static class Audits {
		PropertyRateAuditResult rateResult;
		ReplacementProposals replacements;
		RangeAuditResult statistic;
		AbstractAuditResult contradictions ;
		IProperty property;
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected Object transform(Object value) {
		IProperty p = (IProperty) value;
		GeneralAuditResult auditResult = (GeneralAuditResult) DefaultUniverse
				.getInstance().getAuditResult();
		if (auditResult == null) {
			DefaultUniverse.getInstance().launchAudit();
			return transform(value);
		}
		Audits audits = new Audits();
		ArrayList<AbstractAuditResult> result = (ArrayList) auditResult.getResults(p.getId(), null, PropertyRateAuditResult.class);
		if ( result != null &&  !result.isEmpty()) {
			audits.rateResult = (PropertyRateAuditResult) result.get(0);
		}
		result = (ArrayList) auditResult.getResults(p.getId(),null,	RangeAuditResult.class);
		if (result != null && !result.isEmpty()) {
			audits.statistic = (RangeAuditResult) result.get(0);
		}
		result = (ArrayList) auditResult.getResults(p.getId(), DisambiguationValueAudit.ID, ReplacementProposals.class);
		if ( result != null && !result.isEmpty()) {
			audits.replacements = (ReplacementProposals) result.get(0);
		}
		result = (ArrayList) auditResult.getResults( p.getId(),null, AbstractAuditResult.class );
		if( result !=null ){
			for( AbstractAuditResult res : result )
			{
				if( res != null && res.getAuditId() != null && res.getAuditId().equals(ContradictionsDetectionAudit.ID) )
				{
					audits.contradictions = res ;
					break ;
				}
			}
		}
		audits.property=p;
		return audits;
	}

	
}
